<!--  活动列表组件  -->
<template>
  <div>
  <div id="search-card">

          <div id="search-content">

                 <el-form v-model="search" :inline="true">
                   <el-form-item label="活动编号:">
                     <el-input v-model="search.actId" />
                   </el-form-item>

                   <el-form-item label="活动标题">
                     <el-input v-model="search.actTitle" />
                   </el-form-item>

                   <el-form-item label="负责人姓名">
                     <el-input v-model="search.actPrincipalName"/>
                   </el-form-item>

                   <el-form-item label="活动地点">
                     <el-input v-model="search.actAddress" />
                   </el-form-item>

                     <el-form-item>
                       <el-button type="primary" style="margin-left:10px" @click="conditionQuery">查找</el-button>
                     </el-form-item>


                   </el-form>
               </div>
     </div>
  <div class=''>
    <el-table
      :loading="listLoading"
      :data="list.slice((this.currentPage-1)*pagesize,currentPage*pagesize)"
      element-loading-text="Loading"
      border
      fit
      highlight-current-row
    >
      <el-table-column
        align="center"
        prop="actId"
        label="活动编号"
        width="100px"
      />

      <el-table-column
        align="center"
        prop="actTitle"
        label="活动名称"
        width="200px"
      />

      <el-table-column
        align="center"
        prop="actType"
        label="活动级别"
        width="100px"
      >
        <template slot-scope="scope">
          <span v-if="scope.row.actType=='1'">学部级</span>
          <span v-if="scope.row.actType=='2'" style="color: blue;"><b>校级</b></span>
        </template>
      </el-table-column>

      <el-table-column
        align="center"
        prop="actMemberMax"
        label="活动人数"
        width="100px"
      />

      <el-table-column
        align="center"
        prop="actPrincipalName"
        label="活动负责人"
         width="120px"
      />

      <el-table-column
        align="center"
        prop="actPrincipalPhone"
        label="负责人电话"
        width="150px"
      />

      <el-table-column
        align="center"
        prop="actAddress"
        label="活动地点"
        width="300px"
      />

      <el-table-column
        align="center"
        prop="actMemberWay"
        label="录取方式"
         width="100px"
      >
        <template slot-scope="scope">
          <span v-if="scope.row.actMemberWay=='1'" >手动审核</span>
          <span v-if="scope.row.actMemberWay=='2'" >无需审核</span>
        </template>
      </el-table-column>

      <el-table-column
        align="center"
        prop="actStatus"
        label="活动状态"
         width="100px"
      >
        <template slot-scope="scope">
          <span v-if="scope.row.actStatus=='0'" >待审核</span>
          <span v-if="scope.row.actStatus=='1'" >报名中</span>
          <span v-if="scope.row.actStatus=='2'" >已截止</span>
          <span v-if="scope.row.actStatus=='3'" >已结束</span>
        </template>
      </el-table-column>


      <el-table-column align="center" label="操作" >
        <template slot-scope="Scope">
          <el-button type="primary" icon="el-icon-search" @click="getActivityInfo(Scope.row.actId)" size="mini">详情</el-button>
        </template>
      </el-table-column>
    </el-table>

    <div id="pages">
      <el-pagination
        :current-page="currentPage"
        :page-sizes="[10]"
        :page-size="pagesize"
        layout="total, sizes,prev, pager, next"
        :total="list.length"
        prev-text="上一页"
        next-text="下一页"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </div>
  </div>
  <activity-info ref="info"  :actId='actId' :show='show'></activity-info>
  </div>

</template>

<script>
//这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
//例如：import 《组件名称》 from '《组件路径》';
import { getAllActivitybyActPartId,conditionSearchActivity } from '../../api/act.js'
import { getAllActivity } from '../../api/act.js'
import Info from '../../components/activity/info.vue'
  export default {
     name:'',
    //import引入的组件需要注入到对象中才能使用
    components: {
      'activity-info': Info
    },
    data() {
      //这里存放数据
      return {
        actId:'',
        show:false,
        dialogFormVisible:false,
        search:{},
        listLoading:false,
        list:[],
        currentPage: 1, // 默认显示页面为1
        pagesize: 10, //    每页的数据条数
        search:{}
      }
    },
    props:{
        type:String
    },
    //监听属性 类似于data概念
    computed: {},
    //监控data中的数据变化
    watch: {},
    //方法集合
    methods: {
      // 每页下拉显示数据
      handleSizeChange (size) {
            this.pagesize = size
      },
          // 点击第几页
      handleCurrentChange(currentPage) {
            console.log(this)
            this.currentPage = currentPage
      },
      handleClick(row) {
            console.log(row)
      },

      getPartActivity(){
        getAllActivitybyActPartId().then((data)=>{
          this.list=data.obj
          this.listLoading=false
        })
      },

      getAllActivity(){
        getAllActivity().then((data)=>{
          this.list=data.obj
          this.listLoading=false
        })
      },

      getActivityInfo(actId){
            this.$refs.info.showInfo(actId)
      },

      conditionQuery(){
            conditionSearchActivity(this.search).then((data)=>{
              this.list=data.obj
            })
      }
    },
    //生命周期 - 创建完成（可以访问当前this实例）
    created() {
      switch(this.type){
        case "part":this.getPartActivity();break;
        case "school":this.getAllActivity();break;
      }
    },
    //生命周期 - 挂载完成（可以访问DOM元素）
    mounted() {},
    beforeCreate() {}, //生命周期 - 创建之前
    beforeMount() {}, //生命周期 - 挂载之前
    beforeUpdate() {}, //生命周期 - 更新之前
    updated() {}, //生命周期 - 更新之后
    beforeDestroy() {}, //生命周期 - 销毁之前
    destroyed() {}, //生命周期 - 销毁完成
    activated() {}, //如果页面有keep-alive缓存功能，这个函数会触发
  }
</script>
<style scoped>

</style>
